//
//  DYJSerialTableViewCell.m
//  Piece
//
//  Created by dllo on 16/6/7.
//  Copyright © 2016年 Northeast Dianli University. All rights reserved.
//

#import "DYJSerialTableViewCell.h"

@implementation DYJSerialTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        self.layer.masksToBounds = YES;
        self.layer.cornerRadius = 5;
        //连载
        self.serialImageView = [[UIImageView alloc] init];
        self.serialImageView.image = [UIImage imageNamed:@"read_serial"];
        [self.contentView addSubview:_serialImageView];
        
        self.serialTitleLabel = [[UILabel alloc] init];
        self.serialTitleLabel.numberOfLines = 0;
        self.serialTitleLabel.font = [UIFont systemFontOfSize:16];
        [self.contentView addSubview:_serialTitleLabel];
        
        
        self.serialAuthorLabel = [[UILabel alloc] init];
        self.serialAuthorLabel.textColor = [UIColor colorWithRed:0.14 green:0.63 blue:0.91 alpha:1.00];
        self.serialAuthorLabel.font = [UIFont systemFontOfSize:14];
        self.serialAuthorLabel.numberOfLines = 0;
        [self.contentView addSubview:_serialAuthorLabel];
        
        self.serialContentLabel = [[UILabel alloc] init];
        self.serialContentLabel.textColor = [UIColor colorWithRed:0.75 green:0.75 blue:0.75 alpha:1.00];
        self.serialContentLabel.font = [UIFont systemFontOfSize:14];
        self.serialContentLabel.numberOfLines = 0;
        [self.contentView addSubview:_serialContentLabel];
        
        self.serialLineView = [[UIView alloc] init];
        self.serialLineView.backgroundColor = [UIColor colorWithRed:0.91 green:0.91 blue:0.91 alpha:1.00];
        [self.contentView addSubview:_serialLineView];
    }
    return self;
}
- (void)setSerialModel:(DYJSerialModel *)serialModel
{
    if (_serialModel != serialModel) {
        _serialModel = serialModel;
        self.serialTitleLabel.text = _serialModel.title;
        self.serialAuthorLabel.text = _serialModel.authorModel.user_name;
        self.serialContentLabel.text = _serialModel.excerpt;
    }
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    self.serialImageView.frame = CGRectMake(10, 13, 48, 48);
    self.serialTitleLabel.frame = CGRectMake(60, 10, ScreenWidth - 90, 49);

    self.serialAuthorLabel.frame = CGRectMake(self.serialTitleLabel.frame.origin.x, self.serialTitleLabel.frame.origin.y + self.serialTitleLabel.frame.size.height, self.serialTitleLabel.frame.size.width, 20);
    //规定字体的大小样式:
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:14], NSFontAttributeName,nil];
    CGRect serialRect = [self.serialContentLabel.text boundingRectWithSize:CGSizeMake(self.serialTitleLabel.frame.size.width - 3, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    self.serialContentLabel.frame = CGRectMake(self.serialTitleLabel.frame.origin.x, self.serialAuthorLabel.frame.origin.y + self.serialAuthorLabel.frame.size.height + 8, serialRect.size.width, serialRect.size.height);
    self.serialLineView.frame = CGRectMake(self.serialTitleLabel.frame.origin.x, self.serialContentLabel.frame.origin.y + self.serialContentLabel.frame.size.height + 10, ScreenWidth - 20 - self.serialTitleLabel.frame.origin.x - 20, 1);
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
